package org.example.im.repository;

import org.example.im.entity.Message;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface MessageRepository extends JpaRepository<Message, Long> {
    
    @Query("SELECT m FROM Message m WHERE (m.senderId = ?1 AND m.receiverId = ?2) OR (m.senderId = ?2 AND m.receiverId = ?1) ORDER BY m.sendTime")
    List<Message> findPrivateMessages(Long userId1, Long userId2);
    
    @Query("SELECT m FROM Message m WHERE m.chatType = 1 ORDER BY m.sendTime")
    List<Message> findGroupMessages();
} 